package com.we.scrm.web;

import com.we.scrm.common.util.IdUtil;
import com.we.scrm.common.util.JsonView;
import com.we.scrm.domain.WechatConfig;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

@Controller
public class WechatConfigController extends AbstractController {
    //定位到微信配置页面
    @GetMapping("/wechatConfig")
    public ModelAndView config(){
        return prepareModelAndView("wechatConfig");
    }

    //获取 微信配置信息
    @PostMapping("/wechat/config")
    @ResponseBody
    public String getConfig(){
        WechatConfig wechatConfig = wechatConfigService.getWechatConfig();
        return JsonView.successJson(wechatConfig);
    }
    //修改 微信配置信息
    @PostMapping("/wechat/update")
    @ResponseBody
    public String update(WechatConfig wechatConfig){
        WechatConfig wc = wechatConfigService.getWechatConfig();
        if(null == wc){
            wechatConfig.setId(1L);
            this.wechatConfigService.create(wechatConfig);
        }else {
            this.wechatConfigService.update(wechatConfig);
        }
        return JsonView.successJson(wechatConfig);
    }


}
